package com.yumeno.market_goods.config.web;

import com.yumeno.market_goods.consts.GoodsConsts;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

//WebMvc配置类
@SpringBootConfiguration
public class WebMvcConfig implements WebMvcConfigurer {
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**").allowedOrigins("*")
                .allowedMethods("GET","POST","HEAD","PUT","DELETE","OPTIONS")
                .allowCredentials(false).maxAge(3600);
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
       //你要代理的静态资源路径(虚拟路径)，项目中如果出现此(虚拟)路径，那他会映射到真正的路径
        // /upload/**/ 这个虚拟路径将会被映射到，默认是linux磁盘路径
        String docPath= GoodsConsts.getConfigUploadPath();
        System.out.println("图片上传路径为"+docPath);
        registry.addResourceHandler("/upload/**").addResourceLocations(docPath);
    }
}
